using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace Macaw.Moss2007.ContentCopySolution
{
    class ContentCopyFeatureReceiver : SPFeatureReceiver
    {

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            SPList bllist = null;
            try
            {
                bllist = site.RootWeb.GetList("/Lists/ContentCopy");
            }
            catch
            {
                bllist = null;
            }

            if (bllist == null)
            {
                Guid blguid = site.RootWeb.Lists.Add("ContentCopy", "ContentCopy", SPListTemplateType.GenericList);
                SPContentType CTContentCopy = site.RootWeb.ContentTypes["ContentCopyDefinition"];
                bllist = site.RootWeb.Lists[blguid];
                bllist.ContentTypes.Add(CTContentCopy);
                bllist.Update();
                bllist = site.RootWeb.Lists[blguid];
                for (int idx=bllist.ContentTypes.Count-1;idx>=0;idx--)
                {
                    if (bllist.ContentTypes[idx].Parent.Id != CTContentCopy.Id)
                    {
                        bllist.ContentTypes.Delete(bllist.ContentTypes[idx].Id);
                    }
                }
                bllist.Update();
            }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {

        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {

        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {

        }
    }
}
